package com.northone.statistics.adapter;

import java.util.List;

import com.northone.statistics.R;
import com.northone.statistics.doman.WeekData;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class StatisListAdapter extends BaseAdapter {
	private List<WeekData> monthStatis;
	private Context context;

	public StatisListAdapter(List<WeekData> monthStatis, Context context) {
		this.monthStatis = monthStatis;
		this.context = context;
	}

	@Override
	public int getCount() {
		return monthStatis.size();
	}

	@Override
	public WeekData getItem(int position) {
		return monthStatis.size() <= 0 ? null : monthStatis.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = View.inflate(context, R.layout.monthstatis_item, null);
			holder.month = (TextView) convertView.findViewById(R.id.tv_month);
			holder.normalNum = (TextView) convertView.findViewById(R.id.tv_normalNum);
			holder.baptismNum = (TextView) convertView.findViewById(R.id.tv_baptism);
			holder.morningRise = (TextView) convertView.findViewById(R.id.tv_morningRise);
			holder.prayNum = (TextView) convertView.findViewById(R.id.tv_prayNum);
			holder.gospeler = (TextView) convertView.findViewById(R.id.tv_gospeler);
			holder.familyMett = (TextView) convertView.findViewById(R.id.tv_familyMett);
			holder.rankMeet = (TextView) convertView.findViewById(R.id.tv_rankMeet);
			holder.sundayMeet = (TextView) convertView.findViewById(R.id.tv_sundayMeet);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		String[] months = context.getResources().getStringArray(R.array.yearOfMonth);
		WeekData item = getItem(monthStatis.size() - 1);

		holder.month.setText(months[position]);
		if (item == null) {
			holder.normalNum.setVisibility(View.GONE);
			holder.baptismNum.setVisibility(View.GONE);
			holder.morningRise.setVisibility(View.GONE);
			holder.prayNum.setVisibility(View.GONE);
			holder.gospeler.setVisibility(View.GONE);
			holder.familyMett.setVisibility(View.GONE);
			holder.rankMeet.setVisibility(View.GONE);
			holder.sundayMeet.setVisibility(View.GONE);
		} else {
			holder.normalNum.setText("正常聚会人数:" + item.normalNum);
			holder.baptismNum.setText("受浸人数:" + item.baptismNum);
			holder.morningRise.setText("晨兴人数:" + item.morningRiseNum);
			holder.prayNum.setText("参加祷告人数:" + item.prayNum);
			holder.gospeler.setText("传福音人数:" + item.gospelerNum);
			holder.familyMett.setText("家聚会次数:" + item.familyMettNum);
			holder.rankMeet.setText("排聚会次数:" + item.rankMeetNum);
			holder.sundayMeet.setText("参加主日人数:" + item.sundayMeetNum);

			holder.normalNum.setVisibility(View.VISIBLE);
			holder.baptismNum.setVisibility(View.VISIBLE);
			holder.morningRise.setVisibility(View.VISIBLE);
			holder.prayNum.setVisibility(View.VISIBLE);
			holder.gospeler.setVisibility(View.VISIBLE);
			holder.familyMett.setVisibility(View.VISIBLE);
			holder.rankMeet.setVisibility(View.VISIBLE);
			holder.sundayMeet.setVisibility(View.VISIBLE);
		}
		return convertView;
	}

	public class ViewHolder {
		public TextView month, normalNum, baptismNum, morningRise, prayNum, gospeler, familyMett, rankMeet, sundayMeet;
	}
}
